home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 11 / Info-Mac_XI_Disc_1.cdr_ / Info-Mac XI Disc 1.cdr / Programs / Science & Math / MacEspresso 1.0 / espresso / utility.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-03  |  1.5 KB  |  61 lines  |  [TEXT/R*ch]

  1. #ifndef UTILITY_H
  2. #define UTILITY_H
  3.  
  4. /*
  5.  *  assumes the memory manager is libmm.a
  6.  *    - allows malloc(0) or realloc(obj, 0)
  7.  *    - catches out of memory (and calls MMout_of_memory())
  8.  *    - catch free(0) and realloc(0, size) in the macros
  9.  */
  10. #define NIL(type)        ((type *) 0)
  11. #define ALLOC(type, num)    \
  12.     ((type *) malloc(sizeof(type) * (num)))
  13. #define REALLOC(type, obj, num)    \
  14.     (obj) ? ((type *) realloc((char *) obj, sizeof(type) * (num))) : \
  15.         ((type *) malloc(sizeof(type) * (num)))
  16. #define FREE(obj)        \
  17.     if ((obj)) { (void) free((char *) (obj)); (obj) = 0; }
  18.  
  19. #include "ansi.h"
  20.  
  21. extern long  util_cpu_time();
  22. extern char *util_path_search
  23.     ARGS((char *program));
  24. extern char *util_file_search
  25.     ARGS((char *file, char *path, char *mode));
  26. extern int   util_pipefork
  27.     ARGS((char **argv, FILE **toCommand, FILE **fromCommand));
  28. extern int   util_csystem
  29.     ARGS((char *command));
  30. extern char *util_print_time
  31.     ARGS((long t));
  32. extern char *util_strsav
  33.     ARGS((char *ptr));
  34. extern char *util_tilde_expand
  35.     ARGS((char *filename));
  36.  
  37. #ifndef NIL_FN
  38. #define NIL_FN(type) ((type (*)()) 0)
  39. #endif /* NIL_FN */
  40.  
  41. #ifndef MAX
  42. #define MAX(a,b)    ((a) > (b) ? (a) : (b))
  43. #endif /* MAX */
  44. #ifndef MIN
  45. #define MIN(a,b)    ((a) < (b) ? (a) : (b))
  46. #endif /* MIN */
  47. #ifndef ABS
  48. #define ABS(a)        ((a) > 0 ? (a) : -(a))
  49. #endif /* ABS */
  50.  
  51.  
  52. #ifdef lint
  53. #undef ALLOC            /* allow for lint -h flag */
  54. #undef REALLOC
  55. #define ALLOC(type, num)    (((type *) 0) + (num))
  56. #define REALLOC(type, obj, num)    ((obj) + (num))
  57. #endif /* lint */
  58.  
  59. #endif
  60.  
  61.